/**
 * Created by Camil on 2018/11/19.
 * 使用ES6新增 Genertor函数,特点是function*,yield
 * 好处:
 *     1.避免使用全局变量,提高安全性
 *     2.代码优雅
 */

let draw = function(count){
    $('.drawCount').text(count);
    let index = 0;
    let start = setInterval(()=>{
        index = Math.floor(Math.random()*10);
        $('.box li').eq(index - 1).addClass('active').siblings('li').removeClass('active');
    },200);

    setTimeout(()=>{
        clearInterval(start);
        let prize = $('ul li').eq(index - 1).text();
        $('.prize').text(prize);
    },5000);
};

//使用 Genertor
 let residue = function* (count){
     while (count > 0){
         count -- ;
         yield draw(count);
     }
 };
let star = residue(5);
$('.drawBtn').click(() =>{
    star.next();
});


